package studio.banner.reference.controller;

import org.springframework.web.bind.annotation.*;
import studio.banner.reference.entity.Document;
import studio.banner.reference.util.ResultBean;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName DocumentController
 * @Deacription 对参考文献进行管理（批量增删改查，Word导入，下载）
 * @Author Baofeng.Wu
 * @Date 2019/10/24 15:21
 **/
@RequestMapping("/document")
@RestController
public class DocumentController extends BaseController {


    /**
     * 添加文献到论文
     *
     * @param docContent
     * @param aggregateId
     * @param session
     * @return
     */
    @PostMapping(value = "/create")
    public ResultBean createDocument(String docContent, Integer aggregateId, HttpSession session) {
        Integer userId = getUserIdBySession(session);
        Document document = new Document(0L, docContent, userId, aggregateId, null, null);
        return new ResultBean(documentService.createDocument(document));
    }


    /**
     * 批量添加文献到论文
     *
     * @param docContent
     * @param thesisId
     * @param httpSession
     * @return
     */
    @PostMapping("/creates")
    public ResultBean createDocumentList(List<String> docContent, Integer thesisId, HttpSession
            httpSession) {
        return new ResultBean();
    }

    /**
     * 删除文献
     *
     * @param docId
     * @return
     */
    @DeleteMapping("/delete")
    public ResultBean deleteDocument(Long docId) {
        return new ResultBean(documentService.deleteDocument(docId));
    }

    /**
     * 批量删除文献
     *
     * @param documentIds
     * @return
     */
    @DeleteMapping("/deletes")
    public ResultBean deleteDocumentList(@RequestBody List<Long> documentIds) {
        Integer userId = 1;
        return new ResultBean(documentService.deleteDocumentList(documentIds, userId));
    }

    /**
     * 修改文献内容
     *
     * @param docContent
     * @param docId
     * @return
     */
    @PutMapping("/update/content")
    public ResultBean updateDocumentContent(String docContent, Long docId) {
        return new ResultBean(documentService.updateContent(docContent, docId));
    }

    /**
     * 查找文献（关键词）
     *
     * @return
     */
    @GetMapping("/search/keyword")
    public ResultBean getDocumentByKeyword(String keyword, HttpSession session) {
        Integer userId = 1;
        return new ResultBean(documentService.getDocumentByKeyword(keyword, userId));
    }

    /**
     * 查找文献（文献ID）
     *
     * @return
     */
    @GetMapping("/search/aggregateId")
    public ResultBean listsDocumentByAggregateId(Integer aggregateId, HttpSession session) {
        Integer userId = getUserIdBySession(session);
        return new ResultBean(documentService.listByAggregateId(aggregateId));
    }
}
